package org.tinygame.herostory.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

/**
 * @author anan
 * @create 2022-05-07 23:46
 */
public class RedisUtil {
    /**
     * 日志对象
     */
    static private final Logger LOGGER = LoggerFactory.getLogger(RedisUtil.class);

    /**
     * Redis 连接池
     */
    static private JedisPool _jedis_pool = null;

    private RedisUtil(){}

    /**
     * 初始化
     */

    static public void init(){
        try {
            _jedis_pool = new JedisPool("127.0.0.1", 6379);
            LOGGER.info("redis 连接成功！");
        }catch (Exception e){
            LOGGER.error(e.getMessage(), e);
        }
    }

    static public Jedis getJedis(){
        if(null == _jedis_pool){
            throw new RuntimeException("_jedisPool 尚未初始化");
        }
        Jedis jedis = _jedis_pool.getResource();
        jedis.auth("lxysdsz1011");
        return jedis;
    }




}
